﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Husb.Framework;
using Husb.Framework.DataAccess;
using System.ComponentModel;

namespace Crawler.Model
{
    [Serializable]
    public class TaskInfo : EntityBase
    {
        #region Private Variables
        private System.Guid id;
        private System.String name;
        private System.Guid? categoryId;
        private System.Int32? taskType;
        private System.String encoding;
        private System.String cookie;
        private System.String loginUrl;
        private System.Boolean? executed;
        private System.Int32? version;
        //[NotUndoable]
        private BindingListView<TaskItemInfo> taskItems;//Binding
        #endregion

        #region Properties
        /// <summary>
        /// 
        /// </summary>		
        public System.Guid Id
        {
            get { return id; }
            set { id = value; }
        }
        /// <summary>
        /// 
        /// </summary>		
        public System.String Name
        {
            get { return name; }
            set { name = value; }
        }
        /// <summary>
        /// 
        /// </summary>		
        public System.Guid? CategoryId
        {
            get { return categoryId; }
            set { categoryId = value; }
        }
        /// <summary>
        /// 
        /// </summary>		
        public System.Int32? TaskType
        {
            get { return taskType; }
            set { taskType = value; }
        }
        /// <summary>
        /// 
        /// </summary>		
        public System.String Encoding
        {
            get { return encoding; }
            set { encoding = value; }
        }
        /// <summary>
        /// 
        /// </summary>		
        public System.String Cookie
        {
            get { return cookie; }
            set { cookie = value; }
        }
        /// <summary>
        /// 
        /// </summary>		
        public System.String LoginUrl
        {
            get { return loginUrl; }
            set { loginUrl = value; }
        }
        /// <summary>
        /// 
        /// </summary>		
        public System.Boolean? Executed
        {
            get { return executed; }
            set { executed = value; }
        }

        /// <summary>
        /// 
        /// </summary>		
        public System.Int32? Version
        {
            get { return version; }
            set { version = value; }
        }

        public BindingListView<TaskItemInfo> TaskItems
        {
            get
            {
                if (taskItems == null)
                {
                    taskItems = new BindingListView<TaskItemInfo>();
                    return taskItems;
                }
                else
                    return taskItems;
            }
            set
            {
                taskItems = value;
            }
        }
        #endregion

        #region GenerateFilterExpression
        /// <summary>
        /// 产生组合查询的条件
        /// </summary>
        /// <param name="task">当前实体类<see cref="TaskInfo"/>TaskInfo</param>
        /// <returns></returns>
        public override string FilterExpression
        {
            get
            {
                string where = "";
                where += DataAccessHelper.GetPartWhereCondition("Id", Id);
                where += DataAccessHelper.GetPartWhereCondition("Name", Name);
                where += DataAccessHelper.GetPartWhereCondition("CategoryId", CategoryId);
                where += DataAccessHelper.GetPartWhereCondition("TaskType", TaskType);
                where += DataAccessHelper.GetPartWhereCondition("Encoding", Encoding);
                where += DataAccessHelper.GetPartWhereCondition("Cookie", Cookie);
                where += DataAccessHelper.GetPartWhereCondition("LoginUrl", LoginUrl);
                where += DataAccessHelper.GetPartWhereCondition("Executed", Executed);

                return where;
            }
        }
        #endregion

        #region Validate
        /// <summary>
        /// 数据验证
        /// </summary> 
        protected override void Validate()
        {
            //AddRule("Price", "Price must be greater than or equal to 0", this.Price < 0);
            AddRule("Name", "任务名称不能为空", string.IsNullOrEmpty(this.Name));
        }
        #endregion
    }
}
